﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MessageSystem.Managed.Infrastructure
{
    public unsafe class XOREncryption
    {
        private static UInt16 _key = 256;

        public static void Encrypt(byte* pbyte, int length)
        {
            if (length > 2)
            {
                UInt16 key = ((UInt16*)pbyte)[0];
                key |= _key;

                int step = (length - 2) / 2;
                for (int i = 2; i < length && step-- > 0; i += 2)
                {
                    UInt16* pData = (UInt16*)(pbyte + i);
                    pData[0] ^= key;
                }
            }
        }
    }
}
